package com.wlcorp.forcazamis.dao.baseinfo.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ibatis.dao.client.DaoException;
import com.wlcorp.forcazamis.dao.baseinfo.ISampleTypeDAO;
import com.wlcorp.forcazamis.domain.baseinfo.SampleType;

public class SampleTypeDAOImpl extends HibernateDaoSupport implements
		ISampleTypeDAO {

	@SuppressWarnings("unchecked")
	public List getSampleTypeList(SampleType sampleType) throws DaoException {
		StringBuffer sqlString = new StringBuffer("from SampleType as sampleType where 1=1 and sampleType.deleteFlag=false");
		if(null != sampleType && null != sampleType.getSampleTypeCode()){
			sqlString.append(" and sampleType.sampleTypeCode = '").append(sampleType.getSampleTypeCode())
				.append("'");
		}
		return getHibernateTemplate().find(sqlString.toString());
	}

	public SampleType getSampleTypeById(Long sampleTypeId) throws DaoException {
		return (SampleType)getHibernateTemplate().get(SampleType.class,sampleTypeId);
	}

	public void deleteSampleType(SampleType sampleType) throws DaoException {
		sampleType.setDeleteFlag(true);
		getHibernateTemplate().update(sampleType);
	}

	public void saveSampleType(SampleType sampleType) throws DaoException {
		getHibernateTemplate().saveOrUpdate(sampleType);
	}

}
